package wnhz.com.business.rebateshop.fragment;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseRVAdapter;
import wnhz.com.business.base.BaseViewHolder;
import wnhz.com.business.base.MyBaseActivity;
import wnhz.com.business.base.MyBaseFragment;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.rebateshop.activity.sort.GoodsTypeActivity;
import wnhz.com.business.rebateshop.activity.sort.RebateSearchActivity;
import wnhz.com.business.view.TranslucentActionBar;

/**
 * Created by lizhenglong on 2017-09-18 0018.
 */

public class SortFragment extends MyBaseFragment implements ActionBarClickListener,View.OnClickListener {
    @BindView(R.id.frag_sort_actionbar)//头部
    TranslucentActionBar frag_sort_actionbar;
    @BindView(R.id.sort_rl_woman)
    RelativeLayout sort_rl_woman;//女人
    @BindView(R.id.sort_rl_man)
    RelativeLayout sort_rl_man;//男人
    @BindView(R.id.sort_rl_shipin)
    RelativeLayout sort_rl_shipin;//饰品
    @BindView(R.id.sort_rl_bag)
    RelativeLayout sort_rl_bag;//箱包
    @BindView(R.id.sort_rl_replacement)
    RelativeLayout sort_rl_replacement;//配件
    @BindView(R.id.sort_rl_jiaju)
    RelativeLayout sort_rl_jiaju;//家具
    @BindView(R.id.sort_rl_food)
    RelativeLayout sort_rl_food;//美食
    @BindView(R.id.sort_rl_other)
    RelativeLayout sort_rl_other;//其他

    @BindView(R.id.frag_sort_midimg)
    ImageView frag_sort_midimg;//中部图片
    @BindView(R.id.sort_lv_list)
    RecyclerView sort_lv_list;//底部列表

    private BaseRVAdapter adapter;

    private MyBaseActivity activity;
    private List<String> testlist = new ArrayList<>();


    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_rebate_sort,container,false);
        ButterKnife.bind(this,view);
        activity = (MyBaseActivity) getActivity();
        frag_sort_actionbar.setData("", 0, null, 1, null,1, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            frag_sort_actionbar.setStatusBarHeight(getStatusBarHeight());
        }
        initview();
        loadTestData();
        Glide.with(activity)
                .load("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/3eb2456c-312f-490d-ab77-4f87e8c98bb4.jpg")
                .into(frag_sort_midimg);
        return view;
    }

    private void initview() {
        sort_rl_woman.setOnClickListener(this);
        sort_rl_man.setOnClickListener(this);
        sort_rl_shipin.setOnClickListener(this);
        sort_rl_bag.setOnClickListener(this);
        sort_rl_replacement.setOnClickListener(this);
        sort_rl_jiaju.setOnClickListener(this);
        sort_rl_food.setOnClickListener(this);
        sort_rl_food.setOnClickListener(this);
        sort_rl_other.setOnClickListener(this);
    }

    @Override
    protected void handleMsg(Message msg) {
        switch (msg.what){
            case 2001:
                sort_lv_list.setLayoutManager(new LinearLayoutManager(activity,LinearLayoutManager.HORIZONTAL,false));
                adapter = new BaseRVAdapter(activity,testlist) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.item_sort_goods;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, int position) {
                        Glide.with(activity).load(testlist.get(position)).into(holder.getImageView(R.id.item_sort_img));
                    }
                };
                sort_lv_list.setAdapter(adapter);
                break;
        }
    }
    private void loadTestData() {
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/3eb2456c-312f-490d-ab77-4f87e8c98bb4.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/bad67013-8075-4949-bace-e5475119e417.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/6aeb5a9e-2655-4cad-9187-d2c234f0eb7a.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/17594e16-7853-446f-a5f9-f467b5d24552.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/ea8e3f3b-0e71-41d8-9a64-e3841575b5ae.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/3c14f5c1-3045-4145-a712-a274b14983ed.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/eaf2f813-ed71-40f8-9316-21f0c04bbedb.png");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/9cf93c70-abec-4380-b85b-739bd2e574c3.jpg");
        testlist.add("http://www.dadaofangzhiwang.com/ftpfile/DadaoImage/headimages/3eb2456c-312f-490d-ab77-4f87e8c98bb4.jpg");
        testlist.add("http://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJvVusaGiaHqNYLvWZfFlEjmz2O5UdRILKiawRQRg5YhoT8cialYOeNB8tH5PX2Ex2VzjAVZc38LhZtw/0");
        handler.sendEmptyMessage(2001);
    }

    @Override
    public void onLeftClick() {

    }

    @Override
    public void onRightClick() {

    }

    @Override
    public void onEditTextClick() {
        startActivity(new Intent(getActivity(), RebateSearchActivity.class));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.sort_rl_woman:
                startActivity(new Intent(GoodsTypeActivity.createIntent(getActivity(),"女人","1")));
                break;
        }
    }
}
